const axios = require("axios");
const LocalStorage = require('node-localstorage').LocalStorage;
localStorage = new LocalStorage('./scratch');
const service = axios.create({
  baseURL: "http://127.0.0.1:3001",
  timeout: 20 * 1000, // 请求超时时间
});
service.interceptors.request.use(
  (config) => {

    config.headers = {
      "access-control-allow-credentials": true,
      "access-control-allow-headers":
      "Origin, Content-Type, Cookie, X-CSRF-TOKEN, Accept, Authorization, X-XSRF-TOKEN, token, x-requested-with",
      "access-control-allow-methods": "GET, POST, PATCH, PUT, OPTIONS",
      "access-control-allow-origin": "https://tongji.dcloud.net.cn",
      "cache-control": "private, must-revalidate",
      "content-encoding": "gzip",
      "content-type": "application/json",
      date: "Tue, 05 Jan 2021 07:08:00 GMT",
      eagleid: "7d4d8ea616098304797551845e",
      expires: "-1",
      pragma: "no-cache",
      server: "Tengine",
      "timing-allow-origin": "*",
      vary: "Accept-Encoding",
      via: "cache40.l2cn1800[794,0], kunlun6.cn199[798,0]",

    };
    if(localStorage.getItem('token')){
      config.headers.token = localStorage.getItem('token')
    }
    return config;
  },
  (error) => {
    console.log(error); // for debug
    Promise.reject(error);
  }
);
module.exports = service
